package com.gun.management.module.task.api.task;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.gun.management.framework.common.exception.ServiceException;
import com.gun.management.module.member.api.point.MemberPointApi;
import com.gun.management.module.member.api.user.MemberUserApi;
import com.gun.management.module.member.api.user.dto.MemberUserRespDTO;
import com.gun.management.module.member.dal.dataobject.user.MemberUserDO;
import com.gun.management.module.member.dal.mysql.point.MemberPointRecordMapper;
import com.gun.management.module.member.dal.mysql.user.MemberUserMapper;
import com.gun.management.module.member.enums.point.MemberPointBizTypeEnum;
import com.gun.management.module.task.api.TaskApi;
import com.gun.management.module.task.api.dto.TaskReqDTO;
import com.gun.management.module.task.dal.dataobject.taskInfo.TaskInfoDO;
import com.gun.management.module.task.dal.dataobject.taskRewardLog.TaskRewardLogDO;
import com.gun.management.module.task.dal.mysql.taskInfo.TaskInfoMapper;
import com.gun.management.module.task.dal.mysql.taskRewardLog.TaskRewardLogMapper;
import com.gun.management.module.task.dal.mysql.taskRewardRecord.TaskRewardRecordMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.support.TransactionTemplate;
import org.springframework.validation.annotation.Validated;

import jakarta.annotation.Resource;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;


@Service
@Validated
@Slf4j
public class TaskApiImpl implements TaskApi {


    @Resource
    private TaskInfoMapper taskInfoMapper;


    @Resource
    private MemberPointApi memberPointApi;

    @Resource
    private MemberUserApi memberUserApi;

    @Resource
    private MemberPointRecordMapper memberPointRecordMapper;

    @Resource
    private TaskRewardRecordMapper taskRewardRecordMapper;

    @Resource
    private TaskRewardLogMapper taskRewardLogMapper;

    @Resource
    private MemberUserMapper memberUserMapper;

    @Resource
    private TransactionTemplate transactionTemplate;


    /**
     * 参加活动后奖励积分
     * @param reqDTO
     */
    @Override
    @Transactional(rollbackFor = {ServiceException.class,Exception.class})
    public Boolean rewardPointAfteJoinActivity(TaskReqDTO reqDTO) {
        MemberUserRespDTO memberUserRespDTO = new MemberUserRespDTO();
        if (StringUtils.isNotBlank(reqDTO.getUserCode())) {
            memberUserRespDTO = memberUserApi.getUserByUserCode(reqDTO.getUserCode());
        }
        if (memberUserRespDTO  == null && StringUtils.isNotBlank(reqDTO.getPhone())) {
            memberUserRespDTO = memberUserApi.getUserByMobile(reqDTO.getPhone());
        }

        if (memberUserRespDTO.getParentId() == null) {
            log.error("此用户不存在上级邀请人，参与活动后无法对其上级邀请人进行奖励积分操作!");
            return  false;
        }

        LambdaQueryWrapper<TaskInfoDO> taskInfoDOLambdaQueryWrapper = Wrappers.lambdaQuery();
        taskInfoDOLambdaQueryWrapper.eq(TaskInfoDO::getCategoryId,MemberPointBizTypeEnum.JOIN_ACTIVITY_TASK.getType()); // 查询参与活动类型（task_type = 29)
        taskInfoDOLambdaQueryWrapper.eq(TaskInfoDO::getDeleted,0); // 未删除
        taskInfoDOLambdaQueryWrapper.eq(TaskInfoDO::getStatus,0); // 启用

        TaskInfoDO taskInfoDO =  taskInfoMapper.selectOne(taskInfoDOLambdaQueryWrapper);
        if (taskInfoDO == null) {
            log.error("邀请新用户参与活动后相应的任务奖励积分相关的配置信息不存在,无法给上级邀请人奖励积分!");
            return  false;
        }

        LambdaQueryWrapper<TaskRewardLogDO> taskRewardLogDOLambdaQueryWrapper = Wrappers.lambdaQuery();
        taskRewardLogDOLambdaQueryWrapper.eq(TaskRewardLogDO::getUserId,memberUserRespDTO.getParentId());
        taskRewardLogDOLambdaQueryWrapper.eq(TaskRewardLogDO::getSubUserId,memberUserRespDTO.getId());
        taskRewardLogDOLambdaQueryWrapper.eq(TaskRewardLogDO::getTaskId,taskInfoDO.getId());
        taskRewardLogDOLambdaQueryWrapper.eq(TaskRewardLogDO::getTaskType,MemberPointBizTypeEnum.JOIN_ACTIVITY_TASK.getType());
        TaskRewardLogDO taskRewardLogDO = taskRewardLogMapper.selectOne(taskRewardLogDOLambdaQueryWrapper);
        if (taskRewardLogDO != null) {
            log.error("操作已成功执行，不允许重复操作！");
            return false;
        }
        taskRewardLogDO  = new TaskRewardLogDO();
        taskRewardLogDO.setTaskId(taskInfoDO.getId());
        taskRewardLogDO.setTaskType( MemberPointBizTypeEnum.JOIN_ACTIVITY_TASK.getType());
        taskRewardLogDO.setRewardScore(taskInfoDO.getRewardScore());
        taskRewardLogDO.setUserId(memberUserRespDTO.getParentId());
        taskRewardLogDO.setSubUserId(memberUserRespDTO.getId());
        taskRewardLogDO.setRewardTime(LocalDateTime.now());
        taskRewardLogDO.setDayRewardTimes(taskInfoDO.getDayRewardTimes());
        taskRewardLogDO.setMaxRewardTimes(taskInfoDO.getMaxRewardTimes());
        taskRewardLogDO.setCreateTime(LocalDateTime.now());
        taskRewardLogDO.setCreator(String.valueOf(memberUserRespDTO.getId()));

        taskRewardLogMapper.insertAndGetId(taskRewardLogDO);

        // 用户实名认证后给上级用户添加积分(task_type = 7,邀请新用户实名认证)
        memberPointApi.addPoint(memberUserRespDTO.getParentId(), taskInfoDO.getRewardScore(), MemberPointBizTypeEnum.JOIN_ACTIVITY_TASK.getType(),String.valueOf(taskRewardLogDO.getId()));
        return true;
    }

    /**
     * 注销后清除剩余积分
     * @param reqDTO
     */
    @Override
    @Transactional(rollbackFor = {ServiceException.class,Exception.class})
    public Boolean clearPointAfteSignOff(TaskReqDTO reqDTO) {
        MemberUserRespDTO memberUserRespDTO = new MemberUserRespDTO();
        if (StringUtils.isNotBlank(reqDTO.getUserCode())) {
            memberUserRespDTO = memberUserApi.getUserByUserCode(reqDTO.getUserCode());
        }
        if (memberUserRespDTO  == null && StringUtils.isNotBlank(reqDTO.getPhone())) {
            memberUserRespDTO = memberUserApi.getUserByMobile(reqDTO.getPhone());
        }

        if (memberUserRespDTO.getIsLogoff() == null) {
            memberUserRespDTO.setIsLogoff(0);
        }

        LambdaUpdateWrapper<MemberUserDO> memberUserDOLambdaUpdateWrapper1 = new LambdaUpdateWrapper<>();
        memberUserDOLambdaUpdateWrapper1.eq(MemberUserDO::getId,memberUserRespDTO.getId());
        memberUserDOLambdaUpdateWrapper1.eq(MemberUserDO::getIsLogoff,1);

        MemberUserDO memberUserDO =  memberUserMapper.selectOne(memberUserDOLambdaUpdateWrapper1);
        if (memberUserDO != null) {
            log.error("用户已注销,不允许重复操作!");
            return false;
        }

        if (memberUserRespDTO.getPoint() > 0) {
            // 消耗积分
            memberPointApi.reducePoint(memberUserRespDTO.getId(), memberUserRespDTO.getPoint(), MemberPointBizTypeEnum.LOG_OFF_USER.getType(), String.valueOf(memberUserRespDTO.getParentId()));

        }
        LambdaUpdateWrapper<MemberUserDO> memberUserDOLambdaUpdateWrapper = new LambdaUpdateWrapper<>();
        memberUserDOLambdaUpdateWrapper.eq(MemberUserDO::getId,memberUserRespDTO.getId());
        memberUserDOLambdaUpdateWrapper.set(MemberUserDO::getIsLogoff,1);
        memberUserDOLambdaUpdateWrapper.set(MemberUserDO::getPoint,0);

        memberUserMapper.update(null,memberUserDOLambdaUpdateWrapper);

        return true;
    }


    /**
     * 注册后奖励上级邀请人积分
     * @param
     */
    @Override
    public Boolean rewardPointAfterRegistered(TaskReqDTO memberUserRespDTO) {
        LambdaQueryWrapper<TaskInfoDO> taskInfoDOLambdaQueryWrapper = Wrappers.lambdaQuery();
        taskInfoDOLambdaQueryWrapper.eq(TaskInfoDO::getCategoryId,MemberPointBizTypeEnum.INVITE_NEWUSER_POINT.getType()); // 查询邀请用户注册类型（task_type = 6)
        taskInfoDOLambdaQueryWrapper.eq(TaskInfoDO::getDeleted,0); // 未删除
        taskInfoDOLambdaQueryWrapper.eq(TaskInfoDO::getStatus,0); // 启用
        TaskInfoDO taskInfoDO =  taskInfoMapper.selectOne(taskInfoDOLambdaQueryWrapper);
        if (taskInfoDO == null) {
            log.error("邀请新用户注册相应的任务奖励积分相关的配置信息不存在,无法给上级邀请人奖励积分!");
            return  Boolean.FALSE;
        }
/*
        LambdaQueryWrapper<TaskRewardLogDO> taskRewardLogDOLambdaQueryWrapper = Wrappers.lambdaQuery();
        taskRewardLogDOLambdaQueryWrapper.eq(TaskRewardLogDO::getUserId,memberUserRespDTO.getParentId());
        taskRewardLogDOLambdaQueryWrapper.eq(TaskRewardLogDO::getTaskId,taskInfoDO.getId());
        taskRewardLogDOLambdaQueryWrapper.select(TaskRewardLogDO::getUserId,TaskRewardLogDO::getCreateTime
                ,TaskRewardLogDO::getTaskId);
        List<TaskRewardLogDO> taskRewardLogList  = taskRewardLogMapper.selectList(taskRewardLogDOLambdaQueryWrapper);
       if(taskInfoDO.getDayRewardTimes() > 0 ){
            LocalDate today = LocalDate.now();
           List<TaskRewardLogDO>  logs =  taskRewardLogList.stream().filter(
                    obj -> obj.getCreateTime().toLocalDate().equals(today)
            ).collect(Collectors.toList());
           if(logs.size() >= taskInfoDO.getDayRewardTimes()){
               return Boolean.TRUE;
           }
        }
        if(taskInfoDO.getMaxRewardTimes() > 0){
            if(taskRewardLogList.size() >= taskInfoDO.getMaxRewardTimes()){
                return Boolean.TRUE;
            }
        }*/


        TaskRewardLogDO  taskRewardLogDO = new TaskRewardLogDO();
        taskRewardLogDO.setTaskId(taskInfoDO.getId());
        taskRewardLogDO.setTaskType( MemberPointBizTypeEnum.INVITE_NEWUSER_REGISTER.getType());
        taskRewardLogDO.setRewardScore(taskInfoDO.getRewardAfterRegistered());
        taskRewardLogDO.setUserId(memberUserRespDTO.getParentId());
        taskRewardLogDO.setSubUserId(memberUserRespDTO.getMemberId());
        taskRewardLogDO.setRewardTime(LocalDateTime.now());
        taskRewardLogDO.setDayRewardTimes(taskInfoDO.getDayRewardTimes());
        taskRewardLogDO.setMaxRewardTimes(taskInfoDO.getMaxRewardTimes());
        taskRewardLogDO.setCreateTime(LocalDateTime.now());
        taskRewardLogDO.setCreator("0");
        Boolean execute = transactionTemplate.execute(e -> {
            taskRewardLogMapper.insert(taskRewardLogDO);
           // 用户注册后给上级用户添加积分(task_type = 6,邀请新用户注册)
            memberPointApi.addPoint(memberUserRespDTO.getParentId(),
                taskInfoDO.getRewardAfterRegistered(),
                MemberPointBizTypeEnum.INVITE_NEWUSER_REGISTER.getType(),memberUserRespDTO.getBizId());
            return Boolean.TRUE;
        });
        return execute;
    }



    /**
     * 实名认证后奖励积分
     * @param reqDTO
     */
    @Override
    @Transactional(rollbackFor = {ServiceException.class,Exception.class})
    public Boolean rewardPointAfterAuthed(TaskReqDTO reqDTO) {
        MemberUserRespDTO memberUserRespDTO = new MemberUserRespDTO();
        if (StringUtils.isNotBlank(reqDTO.getUserCode())) {
            memberUserRespDTO = memberUserApi.getUserByUserCode(reqDTO.getUserCode());
        }
        if (memberUserRespDTO  == null && StringUtils.isNotBlank(reqDTO.getPhone())) {
            memberUserRespDTO = memberUserApi.getUserByMobile(reqDTO.getPhone());
        }

        if (memberUserRespDTO.getIsRealName() == null) {
            memberUserRespDTO.setIsRealName(0);
        }

        if (memberUserRespDTO.getParentId() == null) {
            log.error("此用户不存在上级邀请人，实名认证后无法对其上级邀请人进行奖励积分操作!");
            return false;
        }

        if (memberUserRespDTO.getIsRealName().intValue() == 0) { // 如果没有实名认证，则执行实名认证操作
            LambdaUpdateWrapper<MemberUserDO> memberUserDOLambdaUpdateWrapper  = new LambdaUpdateWrapper<>();
            memberUserDOLambdaUpdateWrapper.eq(MemberUserDO::getId,memberUserRespDTO.getId());
            memberUserDOLambdaUpdateWrapper.set(MemberUserDO::getIsRealName,1);
            memberUserMapper.update(null,memberUserDOLambdaUpdateWrapper);
        } else {
            log.error("操作已成功执行，不允许重复操作！");
            return false;
        }


        LambdaQueryWrapper<TaskInfoDO> taskInfoDOLambdaQueryWrapper = Wrappers.lambdaQuery();
        taskInfoDOLambdaQueryWrapper.eq(TaskInfoDO::getCategoryId,1); // 查询邀请用户实名认证类型（task_type = 7)
        taskInfoDOLambdaQueryWrapper.eq(TaskInfoDO::getDeleted,0); // 未删除
        taskInfoDOLambdaQueryWrapper.eq(TaskInfoDO::getStatus,0); // 启用

        TaskInfoDO taskInfoDO =  taskInfoMapper.selectOne(taskInfoDOLambdaQueryWrapper);
        if (taskInfoDO == null) {
            log.error("邀请新用户实名认证相应的任务奖励积分相关的配置信息不存在,无法给上级邀请人奖励积分!");
            return false;
        }

        LambdaQueryWrapper<TaskRewardLogDO> taskRewardLogDOLambdaQueryWrapper = Wrappers.lambdaQuery();
        taskRewardLogDOLambdaQueryWrapper.eq(TaskRewardLogDO::getUserId,memberUserRespDTO.getParentId());
        taskRewardLogDOLambdaQueryWrapper.eq(TaskRewardLogDO::getSubUserId,memberUserRespDTO.getId());
        taskRewardLogDOLambdaQueryWrapper.eq(TaskRewardLogDO::getTaskId,taskInfoDO.getId());
        taskRewardLogDOLambdaQueryWrapper.eq(TaskRewardLogDO::getTaskType,MemberPointBizTypeEnum.INVITE_NEWUSER_REALNAME.getType());

        TaskRewardLogDO taskRewardLogDO = taskRewardLogMapper.selectOne(taskRewardLogDOLambdaQueryWrapper);
        if (taskRewardLogDO != null) {
            log.error("操作已成功执行，不允许重复操作！");
            return false;
        }
        taskRewardLogDO  = new TaskRewardLogDO();
        taskRewardLogDO.setTaskId(taskInfoDO.getId());
        taskRewardLogDO.setTaskType( MemberPointBizTypeEnum.INVITE_NEWUSER_REALNAME.getType());
        taskRewardLogDO.setRewardScore(taskInfoDO.getRewardAfterAuthed());
        taskRewardLogDO.setUserId(memberUserRespDTO.getParentId());
        taskRewardLogDO.setSubUserId(memberUserRespDTO.getId());
        taskRewardLogDO.setRewardTime(LocalDateTime.now());
        taskRewardLogDO.setDayRewardTimes(taskInfoDO.getDayRewardTimes());
        taskRewardLogDO.setMaxRewardTimes(taskInfoDO.getMaxRewardTimes());
        taskRewardLogDO.setCreateTime(LocalDateTime.now());
        taskRewardLogDO.setCreator(String.valueOf(memberUserRespDTO.getId()));

        taskRewardLogMapper.insertAndGetId(taskRewardLogDO);

        // 用户实名认证后给上级用户添加积分(task_type = 7,邀请新用户实名认证)
        memberPointApi.addPoint(memberUserRespDTO.getParentId(), taskInfoDO.getRewardAfterAuthed(), MemberPointBizTypeEnum.INVITE_NEWUSER_REALNAME.getType(),String.valueOf(taskRewardLogDO.getId()));
        return true;
    }



    /**
     * 授信通过后奖励积分
     * @param reqDTO
     */

    @Override
    @Transactional(rollbackFor = {ServiceException.class,Exception.class})
    public Boolean rewardPointAfterGranted(TaskReqDTO reqDTO) {
        MemberUserRespDTO memberUserRespDTO = new MemberUserRespDTO();
        if (StringUtils.isNotBlank(reqDTO.getUserCode())) {
            memberUserRespDTO = memberUserApi.getUserByUserCode(reqDTO.getUserCode());
        }
        if (memberUserRespDTO  == null && StringUtils.isNotBlank(reqDTO.getPhone())) {
            memberUserRespDTO = memberUserApi.getUserByMobile(reqDTO.getPhone());
        }

        if (memberUserRespDTO.getParentId() == null) {
            log.error("此用户不存在上级邀请人，授信后无法对其上级邀请人进行奖励积分操作!");
            return false;
        }

        LambdaQueryWrapper<TaskInfoDO> taskInfoDOLambdaQueryWrapper = Wrappers.lambdaQuery();
        taskInfoDOLambdaQueryWrapper.eq(TaskInfoDO::getCategoryId,1); // 查询邀请用户授信类型（task_type = 8)
        taskInfoDOLambdaQueryWrapper.eq(TaskInfoDO::getDeleted,0); // 未删除
        taskInfoDOLambdaQueryWrapper.eq(TaskInfoDO::getStatus,0); // 启用

        TaskInfoDO taskInfoDO =  taskInfoMapper.selectOne(taskInfoDOLambdaQueryWrapper);
        if (taskInfoDO == null) {
            log.error("邀请新用户授信后，相应的任务奖励积分相关的配置信息不存在，无法给上级邀请人奖励积分!");
            return false;
        }

        LambdaQueryWrapper<TaskRewardLogDO> taskRewardLogDOLambdaQueryWrapper = Wrappers.lambdaQuery();
        taskRewardLogDOLambdaQueryWrapper.eq(TaskRewardLogDO::getUserId,memberUserRespDTO.getParentId());
        taskRewardLogDOLambdaQueryWrapper.eq(TaskRewardLogDO::getSubUserId,memberUserRespDTO.getId());
        taskRewardLogDOLambdaQueryWrapper.eq(TaskRewardLogDO::getTaskId,taskInfoDO.getId());
        taskRewardLogDOLambdaQueryWrapper.eq(TaskRewardLogDO::getTaskType,MemberPointBizTypeEnum.INVITE_NEWUSER_GRANT.getType());

        TaskRewardLogDO taskRewardLogDO = taskRewardLogMapper.selectOne(taskRewardLogDOLambdaQueryWrapper);
        if (taskRewardLogDO != null) {
            log.error("操作已成功执行，不允许重复操作！");
            return false;
        }
        taskRewardLogDO  = new TaskRewardLogDO();
        taskRewardLogDO.setTaskId(taskInfoDO.getId());
        taskRewardLogDO.setTaskType( MemberPointBizTypeEnum.INVITE_NEWUSER_GRANT.getType());
        taskRewardLogDO.setRewardScore(taskInfoDO.getRewardAfterGranted());
        taskRewardLogDO.setUserId(memberUserRespDTO.getParentId());
        taskRewardLogDO.setSubUserId(memberUserRespDTO.getId());
        taskRewardLogDO.setRewardTime(LocalDateTime.now());
        taskRewardLogDO.setDayRewardTimes(taskInfoDO.getDayRewardTimes());
        taskRewardLogDO.setMaxRewardTimes(taskInfoDO.getMaxRewardTimes());
        taskRewardLogDO.setCreateTime(LocalDateTime.now());
        taskRewardLogDO.setCreator(String.valueOf(memberUserRespDTO.getId()));

        taskRewardLogMapper.insertAndGetId(taskRewardLogDO);

        // 用户授信后给上级用户添加积分(task_type = 8,邀请新用户授信)
        memberPointApi.addPoint(memberUserRespDTO.getParentId(), taskInfoDO.getRewardAfterGranted(), MemberPointBizTypeEnum.INVITE_NEWUSER_GRANT.getType(),String.valueOf(taskRewardLogDO.getId()));

        return true;
    }

    /**
     * 提现后奖励积分
     * @param reqDTO
     */
    @Override
    @Transactional(rollbackFor = {ServiceException.class,Exception.class})
    public Boolean rewardPointAfterWithdrawal(TaskReqDTO reqDTO) {
        MemberUserRespDTO memberUserRespDTO = new MemberUserRespDTO();
        if (StringUtils.isNotBlank(reqDTO.getUserCode())) {
            memberUserRespDTO = memberUserApi.getUserByUserCode(reqDTO.getUserCode());
        }
        if (memberUserRespDTO  == null && StringUtils.isNotBlank(reqDTO.getPhone())) {
            memberUserRespDTO = memberUserApi.getUserByMobile(reqDTO.getPhone());
        }

        if (memberUserRespDTO.getParentId() == null) {
            log.error("此用户不存在上级邀请人，提现后无法对其上级邀请人进行奖励积分操作!");
            return false;
        }

        LambdaQueryWrapper<TaskInfoDO> taskInfoDOLambdaQueryWrapper = Wrappers.lambdaQuery();
        taskInfoDOLambdaQueryWrapper.eq(TaskInfoDO::getCategoryId,1); // 查询邀请用户提现类型（task_type = 9)
        taskInfoDOLambdaQueryWrapper.eq(TaskInfoDO::getDeleted,0); // 未删除
        taskInfoDOLambdaQueryWrapper.eq(TaskInfoDO::getStatus,0); // 启用

        TaskInfoDO taskInfoDO =  taskInfoMapper.selectOne(taskInfoDOLambdaQueryWrapper);
        if (taskInfoDO == null) {
            log.error("邀请新用户提现后，相应的任务奖励积分相关的配置信息不存在，无法给上级邀请人奖励积分!");
            return false;
        }

        LambdaQueryWrapper<TaskRewardLogDO> taskRewardLogDOLambdaQueryWrapper = Wrappers.lambdaQuery();
        taskRewardLogDOLambdaQueryWrapper.eq(TaskRewardLogDO::getUserId,memberUserRespDTO.getParentId());
        taskRewardLogDOLambdaQueryWrapper.eq(TaskRewardLogDO::getSubUserId,memberUserRespDTO.getId());
        taskRewardLogDOLambdaQueryWrapper.eq(TaskRewardLogDO::getTaskId,taskInfoDO.getId());
        taskRewardLogDOLambdaQueryWrapper.eq(TaskRewardLogDO::getTaskType,MemberPointBizTypeEnum.INVITE_NEWUSER_WITHDRAWAL.getType());

        TaskRewardLogDO taskRewardLogDO = taskRewardLogMapper.selectOne(taskRewardLogDOLambdaQueryWrapper);
        if (taskRewardLogDO != null) {
            log.error("操作已成功执行，不允许重复操作！");
            return false;
        }
        taskRewardLogDO  = new TaskRewardLogDO();
        taskRewardLogDO.setTaskId(taskInfoDO.getId());
        taskRewardLogDO.setTaskType( MemberPointBizTypeEnum.INVITE_NEWUSER_WITHDRAWAL.getType());
        taskRewardLogDO.setRewardScore(taskInfoDO.getRewardAfterWithdrawal());
        taskRewardLogDO.setUserId(memberUserRespDTO.getParentId());
        taskRewardLogDO.setSubUserId(memberUserRespDTO.getId());
        taskRewardLogDO.setRewardTime(LocalDateTime.now());
        taskRewardLogDO.setDayRewardTimes(taskInfoDO.getDayRewardTimes());
        taskRewardLogDO.setMaxRewardTimes(taskInfoDO.getMaxRewardTimes());
        taskRewardLogDO.setCreateTime(LocalDateTime.now());
        taskRewardLogDO.setCreator(String.valueOf(memberUserRespDTO.getId()));

        taskRewardLogMapper.insertAndGetId(taskRewardLogDO);

        // 用户提现后给上级用户添加积分(task_type = 9,邀请新用户提现)
        memberPointApi.addPoint(memberUserRespDTO.getParentId(), taskInfoDO.getRewardAfterWithdrawal(), MemberPointBizTypeEnum.INVITE_NEWUSER_WITHDRAWAL.getType(),String.valueOf(taskRewardLogDO.getId()));

        return true;
    }
}
